package com.laijiale.controller;

import com.laijiale.dto.RoleInsertDTO;
import com.laijiale.dto.RolePageDTO;
import com.laijiale.dto.RoleUpdateDTO;
import com.laijiale.entity.Role;
import com.laijiale.service.RoleService;
import com.laijiale.vo.RoleSimpleListVO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.laijiale.entity.Role;
import com.laijiale.service.RoleService;

import java.util.List;

/**
 *  控制层。
 *
 * @author laijiale
 * @since 2024-12-22
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Operation(summary ="新增－ 单条",description ="新增一条角色记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody RoleInsertDTO dto) {
        return roleService.insert(dto);
    }
    @Operation(summary="查询－ 单条",description="按主键查询一条角色记录")
    @GetMapping("select/{id}")
    public Role select(@PathVariable("id") Long id) {
        return roleService.select(id);
    }
    @Operation(summary ="查询－简单全查",description="查询全部角色记录")
    @GetMapping("simpleList")
    public List<RoleSimpleListVO> simpleList() {
        return roleService.simpleList();
    }
    @Operation(summary="查询－ 分页",description ="分页查询角色记录")
    @GetMapping("page")
    public Page<Role> page(@Validated RolePageDTO dto) {
        return roleService.page(dto);
    }
    @Operation(summary="修改－单条",description ="按主键修改一条角色记录")
    @PutMapping("update")
    public boolean update(@RequestBody RoleUpdateDTO dto) {
        return roleService.update(dto);
    }
    @Operation(summary="删除－ 单条",description="按主键删除一条角色记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return roleService.delete(id);
    }
    @Operation(summary="删除－ 批量",description ="按主键批量删除角色记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return roleService.deleteBatch(ids);
    }
    @Operation(summary="查询－ 菜单列表",description ="按主键查询角色全部的菜单ID列表")
    @DeleteMapping("listMenuIds/{id}")
    public List<Long> listMenuIds(@PathVariable("id") Long id) {
        return roleService.listMenuIds(id);
    }

}
